﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;
using System.Web.UI.HtmlControls;

namespace PeisongWeb.admin
{
    public partial class sysAdminList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                if (logic.sysAdmin.AdminID==1)
                {
                    rptBind();
                }
                else
                {
                    Library.Script.ClientMsgUrl("没有权限！", "index.aspx");
                    return;
                }
            }
        }
        void rptBind()
        {
            StringBuilder where = new StringBuilder();
            where.Append("1=1");
            if (txt_username.Text.Trim() != "")
                where.AppendFormat("and username='{0}'", txt_username.Text.Trim());
            if (txt_realname.Text.Trim() != "")
                where.AppendFormat("and realname='{0}'", txt_realname.Text.Trim());
            if (txt_email.Text.Trim() != "")
                where.AppendFormat("and email='{0}'", txt_email.Text.Trim());
            if (txt_mobile.Text.Trim() != "")
                where.AppendFormat("and mobile='{0}'", txt_mobile.Text.Trim());
            DataSet ds = logic.sysAdmin.select(where.ToString(), "[disable] asc,departmentId asc,adminId desc", AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex);
            AspNetPager1.RecordCount = Convert.ToInt32(ds.Tables[0].Rows[0][0]);
            rpt_list.DataSource = ds.Tables[1];
            rpt_list.DataBind();

            //for (int i = rpt_list.Items.Count - 1; i > 0; i--)
            //{
            //    HtmlTableCell oCell_previous = rpt_list.Items[i - 1].FindControl("tdName") as HtmlTableCell;
            //    HtmlTableCell oCell = rpt_list.Items[i].FindControl("tdName") as HtmlTableCell;

            //    oCell.RowSpan = (oCell.RowSpan == -1) ? 1 : oCell.RowSpan;
            //    oCell_previous.RowSpan = (oCell_previous.RowSpan == -1) ? 1 : oCell_previous.RowSpan;

            //    if (oCell.InnerText == oCell_previous.InnerText)
            //    {
            //        oCell.Visible = false;
            //        oCell_previous.RowSpan += oCell.RowSpan;
            //    }
            //}

        }
        protected void rpt_list_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            //if (e.CommandName == "Del")
            //{
            //    int id = Convert.ToInt32(e.CommandArgument);
            //    string infor;

            //    logic.sysAdmin.delete(id);
            //    rptBind();
            //    infor = "删除成功！";

            //    Library.Script.ClientMsg(infor);
            //}
            if (e.CommandName == "Disable")
            {
                int id = Convert.ToInt32(e.CommandArgument);
                string infor;

                logic.sysAdmin.IsDisable(id);
                rptBind();
                infor = " 禁用成功！";

                Library.Script.ClientMsg(infor);
            }
            if (e.CommandName == "ErrorTimesToZero")
            {
                int id = Convert.ToInt32(e.CommandArgument);
                logic.sysAdmin.errorTimesToZero(id);
                rptBind();
                Library.Script.ClientMsg("清零成功!");
            }
        }
        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            rptBind();
        }
        protected void lbtn_Search_Click(object sender, EventArgs e)
        {
            rptBind();
        }


        public bool get(object s)
        {
            bool isbool = false;
            bool.TryParse(s.ToString(),out isbool);
            return !(bool)isbool;
        }
    }
}
